package com.safe.first.interfaces.controller;

import com.safe.first.application.dto.cmd.CreateUserCmd;
import com.safe.first.application.service.UserAppService;
import com.safe.first.common.model.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.security.Principal;

/**
 * @author Mickey
 * @since 2022/6/13
 **/
@RestController
@RequestMapping("/user")
@AllArgsConstructor
public class UserController {

    private final UserAppService userAppService;

    @GetMapping("/hello")
    public String hello() {
        return "user hello";
    }

    @GetMapping("/by/{id}")
    public R<?> byId(@PathVariable Long id) {
        return R.OK(userAppService.byId(id));
    }

    @PostMapping("/create")
    public R<?> create(@RequestBody @Valid CreateUserCmd createUser, Principal principal) {
        userAppService.create(createUser);
        return R.OK();
    }
}
